/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package app_99;

import java.sql.*;
import java.util.Calendar;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author 
 */
public class Report {

    Connection conn = null;
    static final int COLUMN_COUNT = 4;
    public String fifthDay = null;
    public String firstDate = null;
    public String secondDate = null;
    public String thirdDate = null;
    public String fourthDate = null;
    
    public Report() {
    }

    public void load(DefaultTableModel model, String currentEstablishment) throws ConnectionPoolException, Exception {
        try {
            conn = ConnectionPool.getInstance().get();

            java.util.Date now = new java.util.Date();
            
            Calendar c1 = Calendar.getInstance();
            c1.add(Calendar.DAY_OF_MONTH, -5);
            java.util.Date fromDate = c1.getTime();
            java.sql.Date mySqlFromDate = new java.sql.Date(fromDate.getTime());

            PreparedStatement stmt = conn.prepareStatement("SELECT RepDate, TotalVisitors, PeekVisitors, AvgVisitors, Income " +
                    "FROM mvpdata " +
                    "WHERE  establishment = ? " + 
                    "AND RepDate > ?");
            stmt.setString(1, currentEstablishment);
            stmt.setDate(2, mySqlFromDate);
            ResultSet rs = stmt.executeQuery();

            while (rs.next()) {
                Object[] row = {rs.getString(1), rs.getInt(2), rs.getInt(3), rs.getFloat(4), rs.getFloat(5)};
                model.addRow(row);
            }

            rs.close();
            stmt.close();
            ConnectionPool.getInstance().release(conn);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
}
